
#include <cassert>

#include <ws2tcpip.h>
#include <iphlpapi.h>

#include "sock/server_socket.h"
#include "sock/inetaddr.h"
#include "sock/addr_resolver.h"

using namespace sock;


/*
bool ServerSocket::run( const char * szHost, const char* szPort ) {

	if( !listen( szHost, szPort ) ){
		return false;	
	}; 

	bool bStop = false;
	while( !bStop ) {

		sockaddr_in peeraddr;
		ZeroMemory( &peeraddr, sizeof( peeraddr ) );
		int socknamelen = sizeof( peeraddr );
		SOCKET newsock = ::accept( srvsock, (sockaddr*)&peeraddr, &socknamelen );
		if( newsock == INVALID_SOCKET  ){
			debugFormatedError( 2, _T("accepting connection failed: accept returned INVALID_SOCKET, supplied error: %s"), WSAGetLastError() );
			closesocket( newsock );
			continue;
		} 

		tm ltm;
		time_t time;
		::time(&time);
		localtime_s( &ltm, &time );
		debug( 3, "connection accepted from %s:%u at %02d:%02d:%02d", inet_ntoa(peeraddr.sin_addr), peeraddr.sin_port, ltm.tm_hour, ltm.tm_min, ltm.tm_sec );
		
		// Client connection has been accepted.
		HandleRequest( newsock );

		// Continue accepting incoming connections (if only server has not been stoped).
	}
	closesocket(srvsock);
	return 0;
}

*/

